#include "StdAfx.h"
#include "CircuitLineDisObj.h"


CCircuitLineDisObj::CCircuitLineDisObj(CCircuitLine *pCircuitLine)
	: CCircuitUnitDisObj((CCircuitUnit *)pCircuitLine)
{
	m_dblLineWidth = pCircuitLine->GetBorderWidth();
	m_dblColor[0] = pCircuitLine->GetColorR();
	m_dblColor[1] = pCircuitLine->GetColorG();
	m_dblColor[2] = pCircuitLine->GetColorB();
}

CCircuitLineDisObj::CCircuitLineDisObj(const CCircuitLineDisObj *pDisObj, CCircuitLine *pCircuitLine/* =NULL */)
	: CCircuitUnitDisObj(pDisObj, (CCircuitUnit *)pCircuitLine)
{

}

CCircuitLineDisObj::~CCircuitLineDisObj(void)
{
}

void CCircuitLineDisObj::Serialize(CArchive & ar)
{
	CCircuitUnitDisObj::Serialize(ar);
}

void CCircuitLineDisObj::Display(CHoopsMap *pHoopsMap)
{
	CCircuitLine *pCirLine = (CCircuitLine *)GetEntityObj();
	if (!pCirLine)
	{
		return;
	}

	HC_KEY key_obj = INVALID_KEY;
	char sCirLineSeg[64];
	sprintf(sCirLineSeg, "line_%d", pCirLine->GetId());
	key_obj = HC_Open_Segment(sCirLineSeg);
		HC_Flush_Contents(".", "everything");

		HC_Insert_Line(pCirLine->GetStartPosX(), pCirLine->GetStartPosY(), 0.0f,
			pCirLine->GetEndPosX(), pCirLine->GetEndPosY(), 0.0f);

		HC_Set_Line_Weight(GetLineWidth());

		eLinePattern patt = pCirLine->GetLinePattern();
		CStringA szLinePattern;
		CWireDisplayObj::GetLinePattrenText(patt, szLinePattern);
		HC_Set_Line_Pattern(szLinePattern);

		char szColorPattern[64];
		sprintf(szColorPattern, "lines = (r=%.2f g=%.2f b=%.2f)",
				GetColorR(), GetColorG(), GetColorB());
		HC_Set_Color(szColorPattern);

	HC_Close_Segment();

	pHoopsMap->Delete(this);
	pHoopsMap->Add(key_obj, this);
}

void CCircuitLineDisObj::Transform(const CMatrix transf)
{

}

CObj *CCircuitLineDisObj::Clone() const
{
	return new CCircuitLineDisObj(this);
}

bool CCircuitLineDisObj::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

eCircuitUnitType CCircuitLineDisObj::GetCircuitUnitType() const
{
	return CIRCUIT_LINE_DISOBJ;
}